<template>
	<div class="content">
		<carousel></carousel>
		<div class="vio-wrap clearfix">
			<comm v-for="(indexdatad,index) in showdata" :key="index" :record="indexdatad"></comm>
		</div>
		
	</div>
</template>

<script>
	import CONFIG from "@/config";
	import axios from 'axios';
	import carousel from './carousel';
	import comm from './comm';
	
	const listNum = 20;
	let doc = "";
	let dis = 0;
	let isAdd = true;


	export default {
	 	data(){
			return{
				indexdata:[],
				showdata:[]
			}
		},
	 	components: { carousel,comm },
	 	mounted(){
			
	 		this.addList()
		},
		created(){
			this.$emit("navs",0)
			this._getNews()
		},
	 	methods:{
	 		_getNews(){
				var url = CONFIG.domain + "?posi=index"
				axios.get(url).then((res) => {
					this.indexdata=res.data.data.list
				}).then(()=>{
					this._ShowList()
				})
	 		},
	 		_ShowList(){
				let con=this.indexdata.splice(0,listNum)
				this.showdata=this.showdata.concat(con)
			},
			addList() {
//				if(!this.hideList.length) {
					window.addEventListener("scroll", () => {
						if(!isAdd){return}
						isAdd=false;
						setTimeout(()=>{
							doc = this.browserRedirect();
						//						1.总高度
//						console.log(doc)
//						console.log("总高度", doc.offsetHeight)
						//						2.当前高度
//						console.log("当前高度", doc.scrollTop)
						isAdd=true;
						dis = ((doc.offsetHeight - doc.scrollTop) / doc.offsetHeight)*10|0
//						console.log("dis", (dis * 10) | 0)
						if(dis <= 4 && this.indexdata.length) {
							this._ShowList()
						}
						},500)
						
						
					})
//				}
			},
			browserRedirect() {
		        var sUserAgent = navigator.userAgent.toLowerCase();
		        var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
		        var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
		        var bIsMidp = sUserAgent.match(/midp/i) == "midp";
		        var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
		        var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
		        var bIsAndroid = sUserAgent.match(/android/i) == "android";
		        var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
		        var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
		        if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
		            return (document.body)
		        } else {
		            return (document.documentElement)
		        }
		    }
	 	},
	 }
</script>

<style lang="scss">
	.vio-wrap{
		width: 100%;
		padding:0 5px;
		margin-top: 10px;
	}
</style>